package com.example.smartgreenhouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.smartgreenhouse.entity.PumpOperationLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PumpOperationLogMapper extends BaseMapper<PumpOperationLog> {

    @Select("SELECT * FROM pump_operation_log WHERE pump_id = #{pumpId} ORDER BY operator_time DESC")
    List<PumpOperationLog> selectByPumpId(Long pumpId);

    @Select("SELECT * FROM pump_operation_log WHERE greenhouse_id = #{greenhouseId} AND operation_type = #{type} ORDER BY operator_time DESC LIMIT 1")
    PumpOperationLog selectLatestByGreenhouseAndType(@Param("greenhouseId") Long greenhouseId,
                                                     @Param("type") String type);
}